package com.ctbu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctbu.entity.BankInfo;
import com.ctbu.entity.UserInfo;
import com.ctbu.mapper.UserInfoMapper;
import com.ctbu.service.UserInfoService;
import com.ctbu.tools.ResponseResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 用户信息表 服务实现类
 * </p>
 *
 * @author lli
 * @since 2024年06月25日
 */
@Service
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements UserInfoService {

    @Autowired
    UserInfoMapper userInfoMapper;
    @Override
    public ResponseResult<Object> selectList(int pageNum, int pageSize, String fullName, String username, String userType, String start, String end) {
        //开启分页
        PageHelper.startPage(pageNum,pageSize);
        //条件查询
        LambdaQueryWrapper<UserInfo> wrapper=new LambdaQueryWrapper<>();
        if(org.apache.commons.lang3.StringUtils.isNotBlank(fullName) ){
            wrapper.like(UserInfo::getFullName,fullName);
        }
        if(org.apache.commons.lang3.StringUtils.isNotBlank(username)){
            wrapper.like(UserInfo::getUsername,username);
        }
        if(org.apache.commons.lang3.StringUtils.isNotBlank(userType)){
            wrapper.like(UserInfo::getUserType,userType);
        }

        //日期-条件1  有开始没结束   ge-大于等于  le-小于等于
        if(org.apache.commons.lang3.StringUtils.isNotBlank(start)&&org.apache.commons.lang3.StringUtils.isBlank(end)){
            wrapper.ge(UserInfo::getCreatedAt,start);
        }
        //日期-条件2  无开始有结束
        if(org.apache.commons.lang3.StringUtils.isBlank(start)&&org.apache.commons.lang3.StringUtils.isNotBlank(end)){
            wrapper.le(UserInfo::getCreatedAt,end);
        }
        //日期-条件3  有开始有结束
        if(org.apache.commons.lang3.StringUtils.isNotBlank(start)&&org.apache.commons.lang3.StringUtils.isNotBlank(end)){
            wrapper.between(UserInfo::getCreatedAt,start,end);
        }
        List<UserInfo> list = userInfoMapper.selectList(wrapper);
        //将查询结果封装到对应分页中
        PageInfo<UserInfo> pageInfo = new PageInfo<>(list);
        return ResponseResult.success(pageInfo,"查询成功");

    }
}
